package com.petter.security.config;

import com.petter.core.entry.User;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author : GD
 * @date :2022/3/1 : 21:06
 */

@Component
public class MyConfigBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

        System.out.println("MyConfigBeanFactoryPostProcessor postProcessBeanFactory");

    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        System.out.println("MyConfigBeanFactoryPostProcessor postProcessBeanDefinitionRegistry");
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(User.class);
        beanDefinitionBuilder.addPropertyValue("name","张三");
        registry.registerBeanDefinition("user2",beanDefinitionBuilder.getBeanDefinition());
    }
}
